#include "DoubleMissile.h"

#include <iostream>
using std::cout;
using std::endl;
#include <random>
using std::random_device;
using std::mt19937;
using std::uniform_int_distribution;
#include <algorithm>
using std::clamp;

#include "Constants.h"


namespace GameObjects {

    DoubleMissile::DoubleMissile(Sea::Coordinates const & coordinates)
    : Missile(coordinates), secondaryMissile(randomizedSecondaryMissileCoordinates(coordinates))
    {
        cout << "  (Secondary Missile)";
    }

    DoubleMissile::DoubleMissile(DoubleMissile const & missile)
    : Missile(missile), secondaryMissile(missile.secondaryMissile)
    {
        cout << "  (Secondary Missile)";
    }

    Sea::Coordinates DoubleMissile::randomizedSecondaryMissileCoordinates(Sea::Coordinates const & primaryCoordinates)
    {
        static random_device randomNumberInitializer;
        static mt19937 randomNumbers(randomNumberInitializer());
        static uniform_int_distribution<int> intMinus1to1(-1, 1);

        int x = (int)(primaryCoordinates.getX()) + intMinus1to1(randomNumbers);
        int y = (int)(primaryCoordinates.getY()) + intMinus1to1(randomNumbers);

        x = clamp(x, 0, int(Constants::seaSizeX) - 1);
        y = clamp(y, 0, int(Constants::seaSizeX) - 1);

        return Sea::Coordinates((unsigned int)(x), (unsigned int)(y));
    }

    // TODO Aufgabe 3:
    //  Definiert die Funktion `checkHit(..)`.
    /*
     ???
     */

    // TODO Aufgabe 3:
    //  Definiert die Funktion `hasHitSomething()`.
    /*
     ???
     */

    // TODO Aufgabe 3:
    //  Definiert die Funktion `output(..)`.
    /*
     ???
     */

}
